package com.dididoctor.doctor.MV;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.widget.Toast;

/**
 * Created by mahuihuang on 15/4/24.
 */
@SuppressLint("ValidFragment")
public class BaseFragment extends Fragment implements IBaseView {

    private Toast mToast = null;
    private ProgressDialog mProgressDialog = null;

    @Override
    public void showToastMessage(final String message) {
        if (getActivity() == null) {
            return;
        }
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (mToast != null) {
                    mToast.cancel();
                    mToast = null;
                }
                mToast = Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT);
                mToast.show();
            }
        });
    }

    @Override
    public void showLoadingDialog(String message) {
        try {
            cancelLoadingDialog();
            if (TextUtils.isEmpty(message)) {
                message = "正在加载...";
            }
            mProgressDialog = ProgressDialog.show(getActivity(), null, message, false, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void cancelLoadingDialog() {
        if (mProgressDialog != null) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
    }

    @Override
    public void onProgress(int bytesWritten, int totalSize) {

    }
}
